package net.yunzhanyi.client.service.impl;

import net.yunzhanyi.client.service.ClientUserService;
import net.yunzhanyi.common.core.utils.ObjectUtils;
import net.yunzhanyi.generic.domain.model.ClientUser;
import net.yunzhanyi.generic.mapper.ClientUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bestct
 * @date 2022/10/3
 * @type 类
 */
@Service
public class ClientUserServiceImpl implements ClientUserService {

    @Autowired
    private ClientUserMapper userMapper;
    @Override
    public ClientUser getUserById(Long uid) {
        ClientUser clientUser = userMapper.selectByUid(uid);
        return clientUser;
    }

    @Override
    public void saveUser(ClientUser clientUser) {
        userMapper.updateByPrimaryKeySelective(clientUser);
    }

    @Override
    public boolean checkNickNameUnique(ClientUser clientUser) {
        ClientUser byNickName = userMapper.selectByNickName(clientUser.getNickName());
        if (ObjectUtils.isNull(byNickName)){
            return true;
        }
        return byNickName.getAid().equals(clientUser.getAid());
    }
}
